<?php

namespace app\company\controller;

use app\company\model\SupplierDividend;
use app\company\validate\SupplierValidate;
use app\service\traits\Crud;
use app\company\model\Supplier as SupplierModel;

class Supplier extends Base
{
    private SupplierModel $model;

    use Crud;

    public function initialize()
    {
        parent::initialize();
        $this->model         = new SupplierModel();
        $this->validateClass = SupplierValidate::class;
        $this->append        = 'type_text';
        $this->withSearch    = 'type,name,id';
        $this->isGs          = true;
    }

    public function format($list): mixed
    {
        return $list->each(function ($item) {
            $item->supplier_user = $item->supplierUsers()->admin()->field('id,mobile,real_name,user_name')->find();
            $item->dividend   = SupplierDividend::where('supplier_id', $item->id)->field('id,investor_id,investor_ratio,service_id,service_ratio,department_ratio,partner_ratio')->find();
        });
    }
}